library(R.matlab)
library(ggplot2)
library(RColorBrewer)
library(reshape2)
library(multcomp)
library(nlme)
library(lme4)
library(ISLR)
library(scales)
library(svglite)
library(ez)
library(Hmisc)
library(dplyr)

## --- User-defined parameters ---

savePlots = 1
plotAll = 0

bPal = brewer.pal(4,'Dark2')

# # Primary-ish color scheme (complementary = no modality or domain similarity)
# condColors_INT = c('#808080', '#71bf6e', '#ff9933')
# condColors_WM = c('#71bf6e', '#ff9933', '#5889b0', '#e94849')

# Separate color schemes for WM and INT
condColors_INT = c('#8c8c8c', '#196619', '#63459b') # grey (no INT), green (temporal), purple (spatial)
condColors_WM = c('#802b00', '#cc4400', '#003399', '#3377ff') # Two-tone (orange family for aud, blue for vis)
condColors_WM_light = c('#e64d00', '#ff7733', '#0055ff', '#99bbff') # 20% lighter
condColors_modality = c('#a83800', '#004de6') # Averages within orange, blue families


## --- Other setup ---

# Set paths based on current machine
compname = Sys.info()
compname = compname[[4]]
if (compname == "DESKTOP-BHR0AU7") {
  loadPath = 'E:/ANL/Experiments/RESULTS/VAST/DATAforR/'
  imgSaveDir = 'E:/ANL/Experiments/RESULTS/VAST/FIGURES/ms/Supplemental/'
} else if (compname == "MSI") {
  loadPath = 'F:/ANL/RESULTS/VAST/DATAforR/'
  imgSaveDir = 'F:/ANL/RESULTS/VAST/FIGURES/ms/Supplemental/'
} else {
  stop('set directories for this machine')
}


## --- Load ERP data ---

# Note, if this variable is not in DATAforR, run "reformat_ERPs_for_R.m"
ERPdata = readMat(paste(loadPath,'avg_eachERP.mat',sep=""))
allconds = unlist(ERPdata$condList)
positions = unlist(ERPdata$max.posList)
tb = t(ERPdata$tb) * 1000
Ntpts = length(tb)
dfLen = dim(ERPdata$erps.aud)[1] * dim(ERPdata$erps.aud)[2]  *dim(ERPdata$erps.aud)[3]
erpsTogether = cond = pos = presmod = rep(NA, dfLen)
startInd = 1
endInd = Ntpts
for (c in 1:length(allconds)) {
  for (p in 1:length(positions)) {
    inds = seq(startInd, endInd, 1)
    cond[inds] = rep(allconds[c], Ntpts)
    pos[inds] = rep(positions[p], Ntpts)
    # Visual WM conditions, ENC/PRB sequences only -- visual stimuli
    if ((grepl("vs_", allconds[c], fixed=TRUE) | grepl("vt_", allconds[c], fixed=TRUE)) &
        !grepl("int_", positions[p], fixed=TRUE)) {
      erpsTogether[inds] = ERPdata$erps.vis[,c,p]
      presmod[inds] = rep('vis', Ntpts)
    } else { # All other stimuli are auditory
      erpsTogether[inds] = ERPdata$erps.aud[,c,p]
      presmod[inds] = rep('aud', Ntpts)
    }
    startInd = endInd + 1;
    endInd = startInd + Ntpts - 1;
  }
}


ERP_df = data.frame('time'=rep(tb, dim(ERPdata$erps.aud)[2] * dim(ERPdata$erps.aud)[3]), 
                    'cond'=cond, 'pos'=pos, 'presmod'=presmod, 'erp'=erpsTogether)
# flip the usual order so visual ERPs get plotted beneath auditory ones
ERP_df$cond = factor(ERP_df$cond, levels=levels(ERP_df$cond)[c(9,8,7,12,11,10,3,2,1,6,5,4)])


### --- PLOTTING --- ###
#________________________________________________________________________________________

  
### --- NO INT --- ###
#________________________________________________________________________________________


# --- ENC S1, No INT ---
dfred = ERP_df[(ERP_df$cond=='at_none' | ERP_df$cond=='as_none' | ERP_df$cond=='vt_none' |
                 ERP_df$cond=='vs_none') & ERP_df$pos=='enc_s1' & (ERP_df$time >= 0 & ERP_df$time <= 300),]
tplot = ggplot(data=dfred, aes(x=time, y=erp)) +
  
  # add on group plots
  geom_line(aes(color=cond, linetype=presmod), size=3) + 
  
  scale_linetype_manual(name='Presentation Modality', labels=c('aud', 'vis'),
                        values=c('solid','longdash'), guide=FALSE) +
  scale_color_manual(name='WM Task', labels=c('vs','vt','as','at'),
                     values=rev(condColors_WM), guide=FALSE) +
  scale_x_continuous(name='Time (ms)', breaks=seq(0,300,by=100), expand=c(0,0)) +
  scale_y_continuous(name='Scalp Potential (?V)', breaks=seq(-10,10,by=10), expand=c(0,0)) +
  coord_cartesian(xlim=c(0,300), ylim=c(-10,12)) +
  theme(panel.background = element_blank(),
        panel.grid.major.y = element_blank(),
        panel.grid.major.x = element_blank(),
        aspect.ratio = 1.25,
        panel.border = element_rect(colour = "black", fill = NA, size=3.5),
        plot.margin=unit(c(2,2,2,2), "lines"),
        legend.direction = 'vertical',
        axis.text.x = element_text(size=40, colour = "black"),
        axis.text.y = element_text(size=40, colour = "black"),
        axis.title.x = element_blank(),
        axis.title.y = element_blank())

windows()
print(tplot)

if (savePlots == 1) {
  ggsave(filename = paste(imgSaveDir,'enc_s1_noINT.svg',sep=""), width=6, height=8, units="in")
}


# --- ENC S2, No INT ---
dfred = ERP_df[(ERP_df$cond=='at_none' | ERP_df$cond=='as_none' | ERP_df$cond=='vt_none' |
                  ERP_df$cond=='vs_none') & ERP_df$pos=='enc_s2' & (ERP_df$time >= 0 & ERP_df$time <= 300),]
tplot = ggplot(data=dfred, aes(x=time, y=erp)) +
  
  # add on group plots
  geom_line(aes(color=cond, linetype=presmod), size=3) + 
  
  scale_linetype_manual(name='Presentation Modality', labels=c('aud', 'vis'),
                        values=c('solid','longdash'), guide=FALSE) +
  scale_color_manual(name='WM Task', labels=c('vs','vt','as','at'),
                     values=rev(condColors_WM), guide=FALSE) +
  scale_x_continuous(name='Time (ms)', breaks=seq(0,300,by=100), expand=c(0,0)) +
  scale_y_continuous(name='Scalp Potential (?V)', breaks=seq(-10,10,by=10), expand=c(0,0)) +
  coord_cartesian(xlim=c(0,300), ylim=c(-10,12)) +
  theme(panel.background = element_blank(),
        panel.grid.major.y = element_blank(),
        panel.grid.major.x = element_blank(),
        aspect.ratio = 1.25,
        panel.border = element_rect(colour = "black", fill = NA, size=3.5),
        plot.margin=unit(c(2,2,2,2), "lines"),
        legend.direction = 'vertical',
        axis.text.x = element_text(size=40, colour = "black"),
        axis.text.y = element_text(size=40, colour = "black"),
        axis.title.x = element_blank(),
        axis.title.y = element_blank())

windows()
print(tplot)

if (savePlots == 1) {
  ggsave(filename = paste(imgSaveDir,'enc_s2_noINT.svg',sep=""), width=6, height=8, units="in")
}


# --- ENC S3, No INT ---
dfred = ERP_df[(ERP_df$cond=='at_none' | ERP_df$cond=='as_none' | ERP_df$cond=='vt_none' |
                  ERP_df$cond=='vs_none') & ERP_df$pos=='enc_s3' & (ERP_df$time >= 0 & ERP_df$time <= 300),]
tplot = ggplot(data=dfred, aes(x=time, y=erp)) +
  
  # add on group plots
  geom_line(aes(color=cond, linetype=presmod), size=3) + 
  
  scale_linetype_manual(name='Presentation Modality', labels=c('aud', 'vis'),
                        values=c('solid','longdash'), guide=FALSE) +
  scale_color_manual(name='WM Task', labels=c('vs','vt','as','at'),
                     values=rev(condColors_WM), guide=FALSE) +
  scale_x_continuous(name='Time (ms)', breaks=seq(0,300,by=100), expand=c(0,0)) +
  scale_y_continuous(name='Scalp Potential (?V)', breaks=seq(-10,10,by=10), expand=c(0,0)) +
  coord_cartesian(xlim=c(0,300), ylim=c(-10,12)) +
  theme(panel.background = element_blank(),
        panel.grid.major.y = element_blank(),
        panel.grid.major.x = element_blank(),
        aspect.ratio = 1.25,
        panel.border = element_rect(colour = "black", fill = NA, size=3.5),
        plot.margin=unit(c(2,2,2,2), "lines"),
        legend.direction = 'vertical',
        axis.text.x = element_text(size=40, colour = "black"),
        axis.text.y = element_text(size=40, colour = "black"),
        axis.title.x = element_blank(),
        axis.title.y = element_blank())

windows()
print(tplot)

if (savePlots == 1) {
  ggsave(filename = paste(imgSaveDir,'enc_s3_noINT.svg',sep=""), width=6, height=8, units="in")
}


# --- ENC S4, No INT ---
dfred = ERP_df[(ERP_df$cond=='at_none' | ERP_df$cond=='as_none' | ERP_df$cond=='vt_none' |
                  ERP_df$cond=='vs_none') & ERP_df$pos=='enc_s4' & (ERP_df$time >= 0 & ERP_df$time <= 300),]
tplot = ggplot(data=dfred, aes(x=time, y=erp)) +
  
  # add on group plots
  geom_line(aes(color=cond, linetype=presmod), size=3) + 
  
  scale_linetype_manual(name='Presentation Modality', labels=c('aud', 'vis'),
                        values=c('solid','longdash'), guide=FALSE) +
  scale_color_manual(name='WM Task', labels=c('vs','vt','as','at'),
                     values=rev(condColors_WM), guide=FALSE) +
  scale_x_continuous(name='Time (ms)', breaks=seq(0,300,by=100), expand=c(0,0)) +
  scale_y_continuous(name='Scalp Potential (?V)', breaks=seq(-10,10,by=10), expand=c(0,0)) +
  coord_cartesian(xlim=c(0,300), ylim=c(-10,12)) +
  theme(panel.background = element_blank(),
        panel.grid.major.y = element_blank(),
        panel.grid.major.x = element_blank(),
        aspect.ratio = 1.25,
        panel.border = element_rect(colour = "black", fill = NA, size=3.5),
        plot.margin=unit(c(2,2,2,2), "lines"),
        legend.direction = 'vertical',
        axis.text.x = element_text(size=40, colour = "black"),
        axis.text.y = element_text(size=40, colour = "black"),
        axis.title.x = element_blank(),
        axis.title.y = element_blank())

windows()
print(tplot)

if (savePlots == 1) {
  ggsave(filename = paste(imgSaveDir,'enc_s4_noINT.svg',sep=""), width=6, height=8, units="in")
}


# --- RET S1, No INT ---
dfred = ERP_df[(ERP_df$cond=='at_none' | ERP_df$cond=='as_none' | ERP_df$cond=='vt_none' |
                  ERP_df$cond=='vs_none') & ERP_df$pos=='ret_s1' & (ERP_df$time >= 0 & ERP_df$time <= 300),]
tplot = ggplot(data=dfred, aes(x=time, y=erp)) +
  
  # add on group plots
  geom_line(aes(color=cond, linetype=presmod), size=3) + 
  
  scale_linetype_manual(name='Presentation Modality', labels=c('aud', 'vis'),
                        values=c('solid','longdash'), guide=FALSE) +
  scale_color_manual(name='WM Task', labels=c('vs','vt','as','at'),
                     values=rev(condColors_WM), guide=FALSE) +
  scale_x_continuous(name='Time (ms)', breaks=seq(0,300,by=100), expand=c(0,0)) +
  scale_y_continuous(name='Scalp Potential (?V)', breaks=seq(-10,10,by=10), expand=c(0,0)) +
  coord_cartesian(xlim=c(0,300), ylim=c(-10,12)) +
  theme(panel.background = element_blank(),
        panel.grid.major.y = element_blank(),
        panel.grid.major.x = element_blank(),
        aspect.ratio = 1.25,
        panel.border = element_rect(colour = "black", fill = NA, size=3.5),
        plot.margin=unit(c(2,2,2,2), "lines"),
        legend.direction = 'vertical',
        axis.text.x = element_text(size=40, colour = "black"),
        axis.text.y = element_text(size=40, colour = "black"),
        axis.title.x = element_blank(),
        axis.title.y = element_blank())

windows()
print(tplot)

if (savePlots == 1) {
  ggsave(filename = paste(imgSaveDir,'ret_s1_noINT.svg',sep=""), width=6, height=8, units="in")
}


# --- RET S2, No INT ---
dfred = ERP_df[(ERP_df$cond=='at_none' | ERP_df$cond=='as_none' | ERP_df$cond=='vt_none' |
                  ERP_df$cond=='vs_none') & ERP_df$pos=='ret_s2' & (ERP_df$time >= 0 & ERP_df$time <= 300),]
tplot = ggplot(data=dfred, aes(x=time, y=erp)) +
  
  # add on group plots
  geom_line(aes(color=cond, linetype=presmod), size=3) + 
  
  scale_linetype_manual(name='Presentation Modality', labels=c('aud', 'vis'),
                        values=c('solid','longdash'), guide=FALSE) +
  scale_color_manual(name='WM Task', labels=c('vs','vt','as','at'),
                     values=rev(condColors_WM), guide=FALSE) +
  scale_x_continuous(name='Time (ms)', breaks=seq(0,300,by=100), expand=c(0,0)) +
  scale_y_continuous(name='Scalp Potential (?V)', breaks=seq(-10,10,by=10), expand=c(0,0)) +
  coord_cartesian(xlim=c(0,300), ylim=c(-10,12)) +
  theme(panel.background = element_blank(),
        panel.grid.major.y = element_blank(),
        panel.grid.major.x = element_blank(),
        aspect.ratio = 1.25,
        panel.border = element_rect(colour = "black", fill = NA, size=3.5),
        plot.margin=unit(c(2,2,2,2), "lines"),
        legend.direction = 'vertical',
        axis.text.x = element_text(size=40, colour = "black"),
        axis.text.y = element_text(size=40, colour = "black"),
        axis.title.x = element_blank(),
        axis.title.y = element_blank())

windows()
print(tplot)

if (savePlots == 1) {
  ggsave(filename = paste(imgSaveDir,'ret_s2_noINT.svg',sep=""), width=6, height=8, units="in")
}


# --- RET S3, No INT ---
dfred = ERP_df[(ERP_df$cond=='at_none' | ERP_df$cond=='as_none' | ERP_df$cond=='vt_none' |
                  ERP_df$cond=='vs_none') & ERP_df$pos=='ret_s3' & (ERP_df$time >= 0 & ERP_df$time <= 300),]
tplot = ggplot(data=dfred, aes(x=time, y=erp)) +
  
  # add on group plots
  geom_line(aes(color=cond, linetype=presmod), size=3) + 
  
  scale_linetype_manual(name='Presentation Modality', labels=c('aud', 'vis'),
                        values=c('solid','longdash'), guide=FALSE) +
  scale_color_manual(name='WM Task', labels=c('vs','vt','as','at'),
                     values=rev(condColors_WM), guide=FALSE) +
  scale_x_continuous(name='Time (ms)', breaks=seq(0,300,by=100), expand=c(0,0)) +
  scale_y_continuous(name='Scalp Potential (?V)', breaks=seq(-10,10,by=10), expand=c(0,0)) +
  coord_cartesian(xlim=c(0,300), ylim=c(-10,12)) +
  theme(panel.background = element_blank(),
        panel.grid.major.y = element_blank(),
        panel.grid.major.x = element_blank(),
        aspect.ratio = 1.25,
        panel.border = element_rect(colour = "black", fill = NA, size=3.5),
        plot.margin=unit(c(2,2,2,2), "lines"),
        legend.direction = 'vertical',
        axis.text.x = element_text(size=40, colour = "black"),
        axis.text.y = element_text(size=40, colour = "black"),
        axis.title.x = element_blank(),
        axis.title.y = element_blank())

windows()
print(tplot)

if (savePlots == 1) {
  ggsave(filename = paste(imgSaveDir,'ret_s3_noINT.svg',sep=""), width=6, height=8, units="in")
}


# --- RET S4, No INT ---
dfred = ERP_df[(ERP_df$cond=='at_none' | ERP_df$cond=='as_none' | ERP_df$cond=='vt_none' |
                  ERP_df$cond=='vs_none') & ERP_df$pos=='ret_s4' & (ERP_df$time >= 0 & ERP_df$time <= 300),]
tplot = ggplot(data=dfred, aes(x=time, y=erp)) +
  
  # add on group plots
  geom_line(aes(color=cond, linetype=presmod), size=3) + 
  
  scale_linetype_manual(name='Presentation Modality', labels=c('aud', 'vis'),
                        values=c('solid','longdash'), guide=FALSE) +
  scale_color_manual(name='WM Task', labels=c('vs','vt','as','at'),
                     values=rev(condColors_WM), guide=FALSE) +
  scale_x_continuous(name='Time (ms)', breaks=seq(0,300,by=100), expand=c(0,0)) +
  scale_y_continuous(name='Scalp Potential (?V)', breaks=seq(-10,10,by=10), expand=c(0,0)) +
  coord_cartesian(xlim=c(0,300), ylim=c(-10,12)) +
  theme(panel.background = element_blank(),
        panel.grid.major.y = element_blank(),
        panel.grid.major.x = element_blank(),
        aspect.ratio = 1.25,
        panel.border = element_rect(colour = "black", fill = NA, size=3.5),
        plot.margin=unit(c(2,2,2,2), "lines"),
        legend.direction = 'vertical',
        axis.text.x = element_text(size=40, colour = "black"),
        axis.text.y = element_text(size=40, colour = "black"),
        axis.title.x = element_blank(),
        axis.title.y = element_blank())

windows()
print(tplot)

if (savePlots == 1) {
  ggsave(filename = paste(imgSaveDir,'ret_s4_noINT.svg',sep=""), width=6, height=8, units="in")
}



### --- AT INT --- ###
#________________________________________________________________________________________


# --- ENC S1, AT INT ---
dfred = ERP_df[(ERP_df$cond=='at_at' | ERP_df$cond=='as_at' | ERP_df$cond=='vt_at' |
                  ERP_df$cond=='vs_at') & ERP_df$pos=='enc_s1' & (ERP_df$time >= 0 & ERP_df$time <= 300),]
tplot = ggplot(data=dfred, aes(x=time, y=erp)) +
  
  # add on group plots
  geom_line(aes(color=cond, linetype=presmod), size=3) + 
  
  scale_linetype_manual(name='Presentation Modality', labels=c('aud', 'vis'),
                        values=c('solid','longdash'), guide=FALSE) +
  scale_color_manual(name='WM Task', labels=c('vs','vt','as','at'),
                     values=rev(condColors_WM), guide=FALSE) +
  scale_x_continuous(name='Time (ms)', breaks=seq(0,300,by=100), expand=c(0,0)) +
  scale_y_continuous(name='Scalp Potential (?V)', breaks=seq(-10,10,by=10), expand=c(0,0)) +
  coord_cartesian(xlim=c(0,300), ylim=c(-10,12)) +
  theme(panel.background = element_blank(),
        panel.grid.major.y = element_blank(),
        panel.grid.major.x = element_blank(),
        aspect.ratio = 1.25,
        panel.border = element_rect(colour = "black", fill = NA, size=3.5),
        plot.margin=unit(c(2,2,2,2), "lines"),
        legend.direction = 'vertical',
        axis.text.x = element_text(size=40, colour = "black"),
        axis.text.y = element_text(size=40, colour = "black"),
        axis.title.x = element_blank(),
        axis.title.y = element_blank())

windows()
print(tplot)

if (savePlots == 1) {
  ggsave(filename = paste(imgSaveDir,'enc_s1_AT.svg',sep=""), width=6, height=8, units="in")
}


# --- ENC S2, AT INT ---
dfred = ERP_df[(ERP_df$cond=='at_at' | ERP_df$cond=='as_at' | ERP_df$cond=='vt_at' |
                  ERP_df$cond=='vs_at') & ERP_df$pos=='enc_s2' & (ERP_df$time >= 0 & ERP_df$time <= 300),]
tplot = ggplot(data=dfred, aes(x=time, y=erp)) +
  
  # add on group plots
  geom_line(aes(color=cond, linetype=presmod), size=3) + 
  
  scale_linetype_manual(name='Presentation Modality', labels=c('aud', 'vis'),
                        values=c('solid','longdash'), guide=FALSE) +
  scale_color_manual(name='WM Task', labels=c('vs','vt','as','at'),
                     values=rev(condColors_WM), guide=FALSE) +
  scale_x_continuous(name='Time (ms)', breaks=seq(0,300,by=100), expand=c(0,0)) +
  scale_y_continuous(name='Scalp Potential (?V)', breaks=seq(-10,10,by=10), expand=c(0,0)) +
  coord_cartesian(xlim=c(0,300), ylim=c(-10,12)) +
  theme(panel.background = element_blank(),
        panel.grid.major.y = element_blank(),
        panel.grid.major.x = element_blank(),
        aspect.ratio = 1.25,
        panel.border = element_rect(colour = "black", fill = NA, size=3.5),
        plot.margin=unit(c(2,2,2,2), "lines"),
        legend.direction = 'vertical',
        axis.text.x = element_text(size=40, colour = "black"),
        axis.text.y = element_text(size=40, colour = "black"),
        axis.title.x = element_blank(),
        axis.title.y = element_blank())

windows()
print(tplot)

if (savePlots == 1) {
  ggsave(filename = paste(imgSaveDir,'enc_s2_AT.svg',sep=""), width=6, height=8, units="in")
}


# --- ENC S3, AT INT ---
dfred = ERP_df[(ERP_df$cond=='at_at' | ERP_df$cond=='as_at' | ERP_df$cond=='vt_at' |
                  ERP_df$cond=='vs_at') & ERP_df$pos=='enc_s3' & (ERP_df$time >= 0 & ERP_df$time <= 300),]
tplot = ggplot(data=dfred, aes(x=time, y=erp)) +
  
  # add on group plots
  geom_line(aes(color=cond, linetype=presmod), size=3) + 
  
  scale_linetype_manual(name='Presentation Modality', labels=c('aud', 'vis'),
                        values=c('solid','longdash'), guide=FALSE) +
  scale_color_manual(name='WM Task', labels=c('vs','vt','as','at'),
                     values=rev(condColors_WM), guide=FALSE) +
  scale_x_continuous(name='Time (ms)', breaks=seq(0,300,by=100), expand=c(0,0)) +
  scale_y_continuous(name='Scalp Potential (?V)', breaks=seq(-10,10,by=10), expand=c(0,0)) +
  coord_cartesian(xlim=c(0,300), ylim=c(-10,12)) +
  theme(panel.background = element_blank(),
        panel.grid.major.y = element_blank(),
        panel.grid.major.x = element_blank(),
        aspect.ratio = 1.25,
        panel.border = element_rect(colour = "black", fill = NA, size=3.5),
        plot.margin=unit(c(2,2,2,2), "lines"),
        legend.direction = 'vertical',
        axis.text.x = element_text(size=40, colour = "black"),
        axis.text.y = element_text(size=40, colour = "black"),
        axis.title.x = element_blank(),
        axis.title.y = element_blank())

windows()
print(tplot)

if (savePlots == 1) {
  ggsave(filename = paste(imgSaveDir,'enc_s3_AT.svg',sep=""), width=6, height=8, units="in")
}


# --- ENC S4, AT INT ---
dfred = ERP_df[(ERP_df$cond=='at_at' | ERP_df$cond=='as_at' | ERP_df$cond=='vt_at' |
                  ERP_df$cond=='vs_at') & ERP_df$pos=='enc_s4' & (ERP_df$time >= 0 & ERP_df$time <= 300),]
tplot = ggplot(data=dfred, aes(x=time, y=erp)) +
  
  # add on group plots
  geom_line(aes(color=cond, linetype=presmod), size=3) + 
  
  scale_linetype_manual(name='Presentation Modality', labels=c('aud', 'vis'),
                        values=c('solid','longdash'), guide=FALSE) +
  scale_color_manual(name='WM Task', labels=c('vs','vt','as','at'),
                     values=rev(condColors_WM), guide=FALSE) +
  scale_x_continuous(name='Time (ms)', breaks=seq(0,300,by=100), expand=c(0,0)) +
  scale_y_continuous(name='Scalp Potential (?V)', breaks=seq(-10,10,by=10), expand=c(0,0)) +
  coord_cartesian(xlim=c(0,300), ylim=c(-10,12)) +
  theme(panel.background = element_blank(),
        panel.grid.major.y = element_blank(),
        panel.grid.major.x = element_blank(),
        aspect.ratio = 1.25,
        panel.border = element_rect(colour = "black", fill = NA, size=3.5),
        plot.margin=unit(c(2,2,2,2), "lines"),
        legend.direction = 'vertical',
        axis.text.x = element_text(size=40, colour = "black"),
        axis.text.y = element_text(size=40, colour = "black"),
        axis.title.x = element_blank(),
        axis.title.y = element_blank())

windows()
print(tplot)

if (savePlots == 1) {
  ggsave(filename = paste(imgSaveDir,'enc_s4_AT.svg',sep=""), width=6, height=8, units="in")
}


# --- INT S1, AT INT ---
dfred = ERP_df[(ERP_df$cond=='at_at' | ERP_df$cond=='as_at' | ERP_df$cond=='vt_at' |
                  ERP_df$cond=='vs_at') & ERP_df$pos=='int_s1' & (ERP_df$time >= 0 & ERP_df$time <= 300),]
tplot = ggplot(data=dfred, aes(x=time, y=erp)) +
  
  # add on group plots
  geom_line(aes(color=cond, linetype=presmod), size=3) + 
  
  scale_linetype_manual(name='Presentation Modality', labels=c('aud', 'vis'),
                        values=c('solid','longdash'), guide=FALSE) +
  scale_color_manual(name='WM Task', labels=c('vs','vt','as','at'),
                     values=rev(condColors_WM), guide=FALSE) +
  scale_x_continuous(name='Time (ms)', breaks=seq(0,300,by=100), expand=c(0,0)) +
  scale_y_continuous(name='Scalp Potential (?V)', breaks=seq(-10,10,by=10), expand=c(0,0)) +
  coord_cartesian(xlim=c(0,300), ylim=c(-10,12)) +
  theme(panel.background = element_blank(),
        panel.grid.major.y = element_blank(),
        panel.grid.major.x = element_blank(),
        aspect.ratio = 1.25,
        panel.border = element_rect(colour = "black", fill = NA, size=3.5),
        plot.margin=unit(c(2,2,2,2), "lines"),
        legend.direction = 'vertical',
        axis.text.x = element_text(size=40, colour = "black"),
        axis.text.y = element_text(size=40, colour = "black"),
        axis.title.x = element_blank(),
        axis.title.y = element_blank())

windows()
print(tplot)

if (savePlots == 1) {
  ggsave(filename = paste(imgSaveDir,'int_s1_AT.svg',sep=""), width=6, height=8, units="in")
}


# --- INT S2, AT INT ---
dfred = ERP_df[(ERP_df$cond=='at_at' | ERP_df$cond=='as_at' | ERP_df$cond=='vt_at' |
                  ERP_df$cond=='vs_at') & ERP_df$pos=='int_s2' & (ERP_df$time >= 0 & ERP_df$time <= 300),]
tplot = ggplot(data=dfred, aes(x=time, y=erp)) +
  
  # add on group plots
  geom_line(aes(color=cond, linetype=presmod), size=3) + 
  
  scale_linetype_manual(name='Presentation Modality', labels=c('aud', 'vis'),
                        values=c('solid','longdash'), guide=FALSE) +
  scale_color_manual(name='WM Task', labels=c('vs','vt','as','at'),
                     values=rev(condColors_WM), guide=FALSE) +
  scale_x_continuous(name='Time (ms)', breaks=seq(0,300,by=100), expand=c(0,0)) +
  scale_y_continuous(name='Scalp Potential (?V)', breaks=seq(-10,10,by=10), expand=c(0,0)) +
  coord_cartesian(xlim=c(0,300), ylim=c(-10,12)) +
  theme(panel.background = element_blank(),
        panel.grid.major.y = element_blank(),
        panel.grid.major.x = element_blank(),
        aspect.ratio = 1.25,
        panel.border = element_rect(colour = "black", fill = NA, size=3.5),
        plot.margin=unit(c(2,2,2,2), "lines"),
        legend.direction = 'vertical',
        axis.text.x = element_text(size=40, colour = "black"),
        axis.text.y = element_text(size=40, colour = "black"),
        axis.title.x = element_blank(),
        axis.title.y = element_blank())

windows()
print(tplot)

if (savePlots == 1) {
  ggsave(filename = paste(imgSaveDir,'int_s2_AT.svg',sep=""), width=6, height=8, units="in")
}


# --- INT S3, AT INT ---
dfred = ERP_df[(ERP_df$cond=='at_at' | ERP_df$cond=='as_at' | ERP_df$cond=='vt_at' |
                  ERP_df$cond=='vs_at') & ERP_df$pos=='int_s3' & (ERP_df$time >= 0 & ERP_df$time <= 300),]
tplot = ggplot(data=dfred, aes(x=time, y=erp)) +
  
  # add on group plots
  geom_line(aes(color=cond, linetype=presmod), size=3) + 
  
  scale_linetype_manual(name='Presentation Modality', labels=c('aud', 'vis'),
                        values=c('solid','longdash'), guide=FALSE) +
  scale_color_manual(name='WM Task', labels=c('vs','vt','as','at'),
                     values=rev(condColors_WM), guide=FALSE) +
  scale_x_continuous(name='Time (ms)', breaks=seq(0,300,by=100), expand=c(0,0)) +
  scale_y_continuous(name='Scalp Potential (?V)', breaks=seq(-10,10,by=10), expand=c(0,0)) +
  coord_cartesian(xlim=c(0,300), ylim=c(-10,12)) +
  theme(panel.background = element_blank(),
        panel.grid.major.y = element_blank(),
        panel.grid.major.x = element_blank(),
        aspect.ratio = 1.25,
        panel.border = element_rect(colour = "black", fill = NA, size=3.5),
        plot.margin=unit(c(2,2,2,2), "lines"),
        legend.direction = 'vertical',
        axis.text.x = element_text(size=40, colour = "black"),
        axis.text.y = element_text(size=40, colour = "black"),
        axis.title.x = element_blank(),
        axis.title.y = element_blank())

windows()
print(tplot)

if (savePlots == 1) {
  ggsave(filename = paste(imgSaveDir,'int_s3_AT.svg',sep=""), width=6, height=8, units="in")
}


# --- RET S1, AT INT ---
dfred = ERP_df[(ERP_df$cond=='at_at' | ERP_df$cond=='as_at' | ERP_df$cond=='vt_at' |
                  ERP_df$cond=='vs_at') & ERP_df$pos=='ret_s1' & (ERP_df$time >= 0 & ERP_df$time <= 300),]
tplot = ggplot(data=dfred, aes(x=time, y=erp)) +
  
  # add on group plots
  geom_line(aes(color=cond, linetype=presmod), size=3) + 
  
  scale_linetype_manual(name='Presentation Modality', labels=c('aud', 'vis'),
                        values=c('solid','longdash'), guide=FALSE) +
  scale_color_manual(name='WM Task', labels=c('vs','vt','as','at'),
                     values=rev(condColors_WM), guide=FALSE) +
  scale_x_continuous(name='Time (ms)', breaks=seq(0,300,by=100), expand=c(0,0)) +
  scale_y_continuous(name='Scalp Potential (?V)', breaks=seq(-10,10,by=10), expand=c(0,0)) +
  coord_cartesian(xlim=c(0,300), ylim=c(-10,12)) +
  theme(panel.background = element_blank(),
        panel.grid.major.y = element_blank(),
        panel.grid.major.x = element_blank(),
        aspect.ratio = 1.25,
        panel.border = element_rect(colour = "black", fill = NA, size=3.5),
        plot.margin=unit(c(2,2,2,2), "lines"),
        legend.direction = 'vertical',
        axis.text.x = element_text(size=40, colour = "black"),
        axis.text.y = element_text(size=40, colour = "black"),
        axis.title.x = element_blank(),
        axis.title.y = element_blank())

windows()
print(tplot)

if (savePlots == 1) {
  ggsave(filename = paste(imgSaveDir,'ret_s1_AT.svg',sep=""), width=6, height=8, units="in")
}


# --- RET S2, AT INT ---
dfred = ERP_df[(ERP_df$cond=='at_at' | ERP_df$cond=='as_at' | ERP_df$cond=='vt_at' |
                  ERP_df$cond=='vs_at') & ERP_df$pos=='ret_s2' & (ERP_df$time >= 0 & ERP_df$time <= 300),]
tplot = ggplot(data=dfred, aes(x=time, y=erp)) +
  
  # add on group plots
  geom_line(aes(color=cond, linetype=presmod), size=3) + 
  
  scale_linetype_manual(name='Presentation Modality', labels=c('aud', 'vis'),
                        values=c('solid','longdash'), guide=FALSE) +
  scale_color_manual(name='WM Task', labels=c('vs','vt','as','at'),
                     values=rev(condColors_WM), guide=FALSE) +
  scale_x_continuous(name='Time (ms)', breaks=seq(0,300,by=100), expand=c(0,0)) +
  scale_y_continuous(name='Scalp Potential (?V)', breaks=seq(-10,10,by=10), expand=c(0,0)) +
  coord_cartesian(xlim=c(0,300), ylim=c(-10,12)) +
  theme(panel.background = element_blank(),
        panel.grid.major.y = element_blank(),
        panel.grid.major.x = element_blank(),
        aspect.ratio = 1.25,
        panel.border = element_rect(colour = "black", fill = NA, size=3.5),
        plot.margin=unit(c(2,2,2,2), "lines"),
        legend.direction = 'vertical',
        axis.text.x = element_text(size=40, colour = "black"),
        axis.text.y = element_text(size=40, colour = "black"),
        axis.title.x = element_blank(),
        axis.title.y = element_blank())

windows()
print(tplot)

if (savePlots == 1) {
  ggsave(filename = paste(imgSaveDir,'ret_s2_AT.svg',sep=""), width=6, height=8, units="in")
}


# --- RET S3, AT INT ---
dfred = ERP_df[(ERP_df$cond=='at_at' | ERP_df$cond=='as_at' | ERP_df$cond=='vt_at' |
                  ERP_df$cond=='vs_at') & ERP_df$pos=='ret_s3' & (ERP_df$time >= 0 & ERP_df$time <= 300),]
tplot = ggplot(data=dfred, aes(x=time, y=erp)) +
  
  # add on group plots
  geom_line(aes(color=cond, linetype=presmod), size=3) + 
  
  scale_linetype_manual(name='Presentation Modality', labels=c('aud', 'vis'),
                        values=c('solid','longdash'), guide=FALSE) +
  scale_color_manual(name='WM Task', labels=c('vs','vt','as','at'),
                     values=rev(condColors_WM), guide=FALSE) +
  scale_x_continuous(name='Time (ms)', breaks=seq(0,300,by=100), expand=c(0,0)) +
  scale_y_continuous(name='Scalp Potential (?V)', breaks=seq(-10,10,by=10), expand=c(0,0)) +
  coord_cartesian(xlim=c(0,300), ylim=c(-10,12)) +
  theme(panel.background = element_blank(),
        panel.grid.major.y = element_blank(),
        panel.grid.major.x = element_blank(),
        aspect.ratio = 1.25,
        panel.border = element_rect(colour = "black", fill = NA, size=3.5),
        plot.margin=unit(c(2,2,2,2), "lines"),
        legend.direction = 'vertical',
        axis.text.x = element_text(size=40, colour = "black"),
        axis.text.y = element_text(size=40, colour = "black"),
        axis.title.x = element_blank(),
        axis.title.y = element_blank())

windows()
print(tplot)

if (savePlots == 1) {
  ggsave(filename = paste(imgSaveDir,'ret_s3_AT.svg',sep=""), width=6, height=8, units="in")
}


# --- RET S4, AT INT ---
dfred = ERP_df[(ERP_df$cond=='at_at' | ERP_df$cond=='as_at' | ERP_df$cond=='vt_at' |
                  ERP_df$cond=='vs_at') & ERP_df$pos=='ret_s4' & (ERP_df$time >= 0 & ERP_df$time <= 300),]
tplot = ggplot(data=dfred, aes(x=time, y=erp)) +
  
  # add on group plots
  geom_line(aes(color=cond, linetype=presmod), size=3) + 
  
  scale_linetype_manual(name='Presentation Modality', labels=c('aud', 'vis'),
                        values=c('solid','longdash'), guide=FALSE) +
  scale_color_manual(name='WM Task', labels=c('vs','vt','as','at'),
                     values=rev(condColors_WM), guide=FALSE) +
  scale_x_continuous(name='Time (ms)', breaks=seq(0,300,by=100), expand=c(0,0)) +
  scale_y_continuous(name='Scalp Potential (?V)', breaks=seq(-10,10,by=10), expand=c(0,0)) +
  coord_cartesian(xlim=c(0,300), ylim=c(-10,12)) +
  theme(panel.background = element_blank(),
        panel.grid.major.y = element_blank(),
        panel.grid.major.x = element_blank(),
        aspect.ratio = 1.25,
        panel.border = element_rect(colour = "black", fill = NA, size=3.5),
        plot.margin=unit(c(2,2,2,2), "lines"),
        legend.direction = 'vertical',
        axis.text.x = element_text(size=40, colour = "black"),
        axis.text.y = element_text(size=40, colour = "black"),
        axis.title.x = element_blank(),
        axis.title.y = element_blank())

windows()
print(tplot)

if (savePlots == 1) {
  ggsave(filename = paste(imgSaveDir,'ret_s4_AT.svg',sep=""), width=6, height=8, units="in")
}


### --- AS INT --- ###
#________________________________________________________________________________________


# --- ENC S1, AS INT ---
dfred = ERP_df[(ERP_df$cond=='at_as' | ERP_df$cond=='as_as' | ERP_df$cond=='vt_as' |
                  ERP_df$cond=='vs_as') & ERP_df$pos=='enc_s1' & (ERP_df$time >= 0 & ERP_df$time <= 300),]
tplot = ggplot(data=dfred, aes(x=time, y=erp)) +
  
  # add on group plots
  geom_line(aes(color=cond, linetype=presmod), size=3) + 
  
  scale_linetype_manual(name='Presentation Modality', labels=c('aud', 'vis'),
                        values=c('solid','longdash'), guide=FALSE) +
  scale_color_manual(name='WM Task', labels=c('vs','vt','as','at'),
                     values=rev(condColors_WM), guide=FALSE) +
  scale_x_continuous(name='Time (ms)', breaks=seq(0,300,by=100), expand=c(0,0)) +
  scale_y_continuous(name='Scalp Potential (?V)', breaks=seq(-10,10,by=10), expand=c(0,0)) +
  coord_cartesian(xlim=c(0,300), ylim=c(-10,12)) +
  theme(panel.background = element_blank(),
        panel.grid.major.y = element_blank(),
        panel.grid.major.x = element_blank(),
        aspect.ratio = 1.25,
        panel.border = element_rect(colour = "black", fill = NA, size=3.5),
        plot.margin=unit(c(2,2,2,2), "lines"),
        legend.direction = 'vertical',
        axis.text.x = element_text(size=40, colour = "black"),
        axis.text.y = element_text(size=40, colour = "black"),
        axis.title.x = element_blank(),
        axis.title.y = element_blank())

windows()
print(tplot)

if (savePlots == 1) {
  ggsave(filename = paste(imgSaveDir,'enc_s1_AS.svg',sep=""), width=6, height=8, units="in")
}


# --- ENC S2, AS INT ---
dfred = ERP_df[(ERP_df$cond=='at_as' | ERP_df$cond=='as_as' | ERP_df$cond=='vt_as' |
                  ERP_df$cond=='vs_as') & ERP_df$pos=='enc_s2' & (ERP_df$time >= 0 & ERP_df$time <= 300),]
tplot = ggplot(data=dfred, aes(x=time, y=erp)) +
  
  # add on group plots
  geom_line(aes(color=cond, linetype=presmod), size=3) + 
  
  scale_linetype_manual(name='Presentation Modality', labels=c('aud', 'vis'),
                        values=c('solid','longdash'), guide=FALSE) +
  scale_color_manual(name='WM Task', labels=c('vs','vt','as','at'),
                     values=rev(condColors_WM), guide=FALSE) +
  scale_x_continuous(name='Time (ms)', breaks=seq(0,300,by=100), expand=c(0,0)) +
  scale_y_continuous(name='Scalp Potential (?V)', breaks=seq(-10,10,by=10), expand=c(0,0)) +
  coord_cartesian(xlim=c(0,300), ylim=c(-10,12)) +
  theme(panel.background = element_blank(),
        panel.grid.major.y = element_blank(),
        panel.grid.major.x = element_blank(),
        aspect.ratio = 1.25,
        panel.border = element_rect(colour = "black", fill = NA, size=3.5),
        plot.margin=unit(c(2,2,2,2), "lines"),
        legend.direction = 'vertical',
        axis.text.x = element_text(size=40, colour = "black"),
        axis.text.y = element_text(size=40, colour = "black"),
        axis.title.x = element_blank(),
        axis.title.y = element_blank())

windows()
print(tplot)

if (savePlots == 1) {
  ggsave(filename = paste(imgSaveDir,'enc_s2_AS.svg',sep=""), width=6, height=8, units="in")
}


# --- ENC S3, AS INT ---
dfred = ERP_df[(ERP_df$cond=='at_as' | ERP_df$cond=='as_as' | ERP_df$cond=='vt_as' |
                  ERP_df$cond=='vs_as') & ERP_df$pos=='enc_s3' & (ERP_df$time >= 0 & ERP_df$time <= 300),]
tplot = ggplot(data=dfred, aes(x=time, y=erp)) +
  
  # add on group plots
  geom_line(aes(color=cond, linetype=presmod), size=3) + 
  
  scale_linetype_manual(name='Presentation Modality', labels=c('aud', 'vis'),
                        values=c('solid','longdash'), guide=FALSE) +
  scale_color_manual(name='WM Task', labels=c('vs','vt','as','at'),
                     values=rev(condColors_WM), guide=FALSE) +
  scale_x_continuous(name='Time (ms)', breaks=seq(0,300,by=100), expand=c(0,0)) +
  scale_y_continuous(name='Scalp Potential (?V)', breaks=seq(-10,10,by=10), expand=c(0,0)) +
  coord_cartesian(xlim=c(0,300), ylim=c(-10,12)) +
  theme(panel.background = element_blank(),
        panel.grid.major.y = element_blank(),
        panel.grid.major.x = element_blank(),
        aspect.ratio = 1.25,
        panel.border = element_rect(colour = "black", fill = NA, size=3.5),
        plot.margin=unit(c(2,2,2,2), "lines"),
        legend.direction = 'vertical',
        axis.text.x = element_text(size=40, colour = "black"),
        axis.text.y = element_text(size=40, colour = "black"),
        axis.title.x = element_blank(),
        axis.title.y = element_blank())

windows()
print(tplot)

if (savePlots == 1) {
  ggsave(filename = paste(imgSaveDir,'enc_s3_AS.svg',sep=""), width=6, height=8, units="in")
}


# --- ENC S4, AS INT ---
dfred = ERP_df[(ERP_df$cond=='at_as' | ERP_df$cond=='as_as' | ERP_df$cond=='vt_as' |
                  ERP_df$cond=='vs_as') & ERP_df$pos=='enc_s4' & (ERP_df$time >= 0 & ERP_df$time <= 300),]
tplot = ggplot(data=dfred, aes(x=time, y=erp)) +
  
  # add on group plots
  geom_line(aes(color=cond, linetype=presmod), size=3) + 
  
  scale_linetype_manual(name='Presentation Modality', labels=c('aud', 'vis'),
                        values=c('solid','longdash'), guide=FALSE) +
  scale_color_manual(name='WM Task', labels=c('vs','vt','as','at'),
                     values=rev(condColors_WM), guide=FALSE) +
  scale_x_continuous(name='Time (ms)', breaks=seq(0,300,by=100), expand=c(0,0)) +
  scale_y_continuous(name='Scalp Potential (?V)', breaks=seq(-10,10,by=10), expand=c(0,0)) +
  coord_cartesian(xlim=c(0,300), ylim=c(-10,12)) +
  theme(panel.background = element_blank(),
        panel.grid.major.y = element_blank(),
        panel.grid.major.x = element_blank(),
        aspect.ratio = 1.25,
        panel.border = element_rect(colour = "black", fill = NA, size=3.5),
        plot.margin=unit(c(2,2,2,2), "lines"),
        legend.direction = 'vertical',
        axis.text.x = element_text(size=40, colour = "black"),
        axis.text.y = element_text(size=40, colour = "black"),
        axis.title.x = element_blank(),
        axis.title.y = element_blank())

windows()
print(tplot)

if (savePlots == 1) {
  ggsave(filename = paste(imgSaveDir,'enc_s4_AS.svg',sep=""), width=6, height=8, units="in")
}


# --- INT S1, AS INT ---
dfred = ERP_df[(ERP_df$cond=='at_as' | ERP_df$cond=='as_as' | ERP_df$cond=='vt_as' |
                  ERP_df$cond=='vs_as') & ERP_df$pos=='int_s1' & (ERP_df$time >= 0 & ERP_df$time <= 300),]
tplot = ggplot(data=dfred, aes(x=time, y=erp)) +
  
  # add on group plots
  geom_line(aes(color=cond, linetype=presmod), size=3) + 
  
  scale_linetype_manual(name='Presentation Modality', labels=c('aud', 'vis'),
                        values=c('solid','longdash'), guide=FALSE) +
  scale_color_manual(name='WM Task', labels=c('vs','vt','as','at'),
                     values=rev(condColors_WM), guide=FALSE) +
  scale_x_continuous(name='Time (ms)', breaks=seq(0,300,by=100), expand=c(0,0)) +
  scale_y_continuous(name='Scalp Potential (?V)', breaks=seq(-10,10,by=10), expand=c(0,0)) +
  coord_cartesian(xlim=c(0,300), ylim=c(-10,12)) +
  theme(panel.background = element_blank(),
        panel.grid.major.y = element_blank(),
        panel.grid.major.x = element_blank(),
        aspect.ratio = 1.25,
        panel.border = element_rect(colour = "black", fill = NA, size=3.5),
        plot.margin=unit(c(2,2,2,2), "lines"),
        legend.direction = 'vertical',
        axis.text.x = element_text(size=40, colour = "black"),
        axis.text.y = element_text(size=40, colour = "black"),
        axis.title.x = element_blank(),
        axis.title.y = element_blank())

windows()
print(tplot)

if (savePlots == 1) {
  ggsave(filename = paste(imgSaveDir,'int_s1_AS.svg',sep=""), width=6, height=8, units="in")
}


# --- INT S2, AS INT ---
dfred = ERP_df[(ERP_df$cond=='at_as' | ERP_df$cond=='as_as' | ERP_df$cond=='vt_as' |
                  ERP_df$cond=='vs_as') & ERP_df$pos=='int_s2' & (ERP_df$time >= 0 & ERP_df$time <= 300),]
tplot = ggplot(data=dfred, aes(x=time, y=erp)) +
  
  # add on group plots
  geom_line(aes(color=cond, linetype=presmod), size=3) + 
  
  scale_linetype_manual(name='Presentation Modality', labels=c('aud', 'vis'),
                        values=c('solid','longdash'), guide=FALSE) +
  scale_color_manual(name='WM Task', labels=c('vs','vt','as','at'),
                     values=rev(condColors_WM), guide=FALSE) +
  scale_x_continuous(name='Time (ms)', breaks=seq(0,300,by=100), expand=c(0,0)) +
  scale_y_continuous(name='Scalp Potential (?V)', breaks=seq(-10,10,by=10), expand=c(0,0)) +
  coord_cartesian(xlim=c(0,300), ylim=c(-10,12)) +
  theme(panel.background = element_blank(),
        panel.grid.major.y = element_blank(),
        panel.grid.major.x = element_blank(),
        aspect.ratio = 1.25,
        panel.border = element_rect(colour = "black", fill = NA, size=3.5),
        plot.margin=unit(c(2,2,2,2), "lines"),
        legend.direction = 'vertical',
        axis.text.x = element_text(size=40, colour = "black"),
        axis.text.y = element_text(size=40, colour = "black"),
        axis.title.x = element_blank(),
        axis.title.y = element_blank())

windows()
print(tplot)

if (savePlots == 1) {
  ggsave(filename = paste(imgSaveDir,'int_s2_AS.svg',sep=""), width=6, height=8, units="in")
}


# --- INT S3, AS INT ---
dfred = ERP_df[(ERP_df$cond=='at_as' | ERP_df$cond=='as_as' | ERP_df$cond=='vt_as' |
                  ERP_df$cond=='vs_as') & ERP_df$pos=='int_s3' & (ERP_df$time >= 0 & ERP_df$time <= 300),]
tplot = ggplot(data=dfred, aes(x=time, y=erp)) +
  
  # add on group plots
  geom_line(aes(color=cond, linetype=presmod), size=3) + 
  
  scale_linetype_manual(name='Presentation Modality', labels=c('aud', 'vis'),
                        values=c('solid','longdash'), guide=FALSE) +
  scale_color_manual(name='WM Task', labels=c('vs','vt','as','at'),
                     values=rev(condColors_WM), guide=FALSE) +
  scale_x_continuous(name='Time (ms)', breaks=seq(0,300,by=100), expand=c(0,0)) +
  scale_y_continuous(name='Scalp Potential (?V)', breaks=seq(-10,10,by=10), expand=c(0,0)) +
  coord_cartesian(xlim=c(0,300), ylim=c(-10,12)) +
  theme(panel.background = element_blank(),
        panel.grid.major.y = element_blank(),
        panel.grid.major.x = element_blank(),
        aspect.ratio = 1.25,
        panel.border = element_rect(colour = "black", fill = NA, size=3.5),
        plot.margin=unit(c(2,2,2,2), "lines"),
        legend.direction = 'vertical',
        axis.text.x = element_text(size=40, colour = "black"),
        axis.text.y = element_text(size=40, colour = "black"),
        axis.title.x = element_blank(),
        axis.title.y = element_blank())

windows()
print(tplot)

if (savePlots == 1) {
  ggsave(filename = paste(imgSaveDir,'int_s3_AS.svg',sep=""), width=6, height=8, units="in")
}


# --- RET S1, AS INT ---
dfred = ERP_df[(ERP_df$cond=='at_as' | ERP_df$cond=='as_as' | ERP_df$cond=='vt_as' |
                  ERP_df$cond=='vs_as') & ERP_df$pos=='ret_s1' & (ERP_df$time >= 0 & ERP_df$time <= 300),]
tplot = ggplot(data=dfred, aes(x=time, y=erp)) +
  
  # add on group plots
  geom_line(aes(color=cond, linetype=presmod), size=3) + 
  
  scale_linetype_manual(name='Presentation Modality', labels=c('aud', 'vis'),
                        values=c('solid','longdash'), guide=FALSE) +
  scale_color_manual(name='WM Task', labels=c('vs','vt','as','at'),
                     values=rev(condColors_WM), guide=FALSE) +
  scale_x_continuous(name='Time (ms)', breaks=seq(0,300,by=100), expand=c(0,0)) +
  scale_y_continuous(name='Scalp Potential (?V)', breaks=seq(-10,10,by=10), expand=c(0,0)) +
  coord_cartesian(xlim=c(0,300), ylim=c(-10,12)) +
  theme(panel.background = element_blank(),
        panel.grid.major.y = element_blank(),
        panel.grid.major.x = element_blank(),
        aspect.ratio = 1.25,
        panel.border = element_rect(colour = "black", fill = NA, size=3.5),
        plot.margin=unit(c(2,2,2,2), "lines"),
        legend.direction = 'vertical',
        axis.text.x = element_text(size=40, colour = "black"),
        axis.text.y = element_text(size=40, colour = "black"),
        axis.title.x = element_blank(),
        axis.title.y = element_blank())

windows()
print(tplot)

if (savePlots == 1) {
  ggsave(filename = paste(imgSaveDir,'ret_s1_AS.svg',sep=""), width=6, height=8, units="in")
}


# --- RET S2, AS INT ---
dfred = ERP_df[(ERP_df$cond=='at_as' | ERP_df$cond=='as_as' | ERP_df$cond=='vt_as' |
                  ERP_df$cond=='vs_as') & ERP_df$pos=='ret_s2' & (ERP_df$time >= 0 & ERP_df$time <= 300),]
tplot = ggplot(data=dfred, aes(x=time, y=erp)) +
  
  # add on group plots
  geom_line(aes(color=cond, linetype=presmod), size=3) + 
  
  scale_linetype_manual(name='Presentation Modality', labels=c('aud', 'vis'),
                        values=c('solid','longdash'), guide=FALSE) +
  scale_color_manual(name='WM Task', labels=c('vs','vt','as','at'),
                     values=rev(condColors_WM), guide=FALSE) +
  scale_x_continuous(name='Time (ms)', breaks=seq(0,300,by=100), expand=c(0,0)) +
  scale_y_continuous(name='Scalp Potential (?V)', breaks=seq(-10,10,by=10), expand=c(0,0)) +
  coord_cartesian(xlim=c(0,300), ylim=c(-10,12)) +
  theme(panel.background = element_blank(),
        panel.grid.major.y = element_blank(),
        panel.grid.major.x = element_blank(),
        aspect.ratio = 1.25,
        panel.border = element_rect(colour = "black", fill = NA, size=3.5),
        plot.margin=unit(c(2,2,2,2), "lines"),
        legend.direction = 'vertical',
        axis.text.x = element_text(size=40, colour = "black"),
        axis.text.y = element_text(size=40, colour = "black"),
        axis.title.x = element_blank(),
        axis.title.y = element_blank())

windows()
print(tplot)

if (savePlots == 1) {
  ggsave(filename = paste(imgSaveDir,'ret_s2_AS.svg',sep=""), width=6, height=8, units="in")
}


# --- RET S3, AS INT ---
dfred = ERP_df[(ERP_df$cond=='at_as' | ERP_df$cond=='as_as' | ERP_df$cond=='vt_as' |
                  ERP_df$cond=='vs_as') & ERP_df$pos=='ret_s3' & (ERP_df$time >= 0 & ERP_df$time <= 300),]
tplot = ggplot(data=dfred, aes(x=time, y=erp)) +
  
  # add on group plots
  geom_line(aes(color=cond, linetype=presmod), size=3) + 
  
  scale_linetype_manual(name='Presentation Modality', labels=c('aud', 'vis'),
                        values=c('solid','longdash'), guide=FALSE) +
  scale_color_manual(name='WM Task', labels=c('vs','vt','as','at'),
                     values=rev(condColors_WM), guide=FALSE) +
  scale_x_continuous(name='Time (ms)', breaks=seq(0,300,by=100), expand=c(0,0)) +
  scale_y_continuous(name='Scalp Potential (?V)', breaks=seq(-10,10,by=10), expand=c(0,0)) +
  coord_cartesian(xlim=c(0,300), ylim=c(-10,12)) +
  theme(panel.background = element_blank(),
        panel.grid.major.y = element_blank(),
        panel.grid.major.x = element_blank(),
        aspect.ratio = 1.25,
        panel.border = element_rect(colour = "black", fill = NA, size=3.5),
        plot.margin=unit(c(2,2,2,2), "lines"),
        legend.direction = 'vertical',
        axis.text.x = element_text(size=40, colour = "black"),
        axis.text.y = element_text(size=40, colour = "black"),
        axis.title.x = element_blank(),
        axis.title.y = element_blank())

windows()
print(tplot)

if (savePlots == 1) {
  ggsave(filename = paste(imgSaveDir,'ret_s3_AS.svg',sep=""), width=6, height=8, units="in")
}


# --- RET S4, AS INT ---
dfred = ERP_df[(ERP_df$cond=='at_as' | ERP_df$cond=='as_as' | ERP_df$cond=='vt_as' |
                  ERP_df$cond=='vs_as') & ERP_df$pos=='ret_s4' & (ERP_df$time >= 0 & ERP_df$time <= 300),]
tplot = ggplot(data=dfred, aes(x=time, y=erp)) +
  
  # add on group plots
  geom_line(aes(color=cond, linetype=presmod), size=3) + 
  
  scale_linetype_manual(name='Presentation Modality', labels=c('aud', 'vis'),
                        values=c('solid','longdash'), guide=FALSE) +
  scale_color_manual(name='WM Task', labels=c('vs','vt','as','at'),
                     values=rev(condColors_WM), guide=FALSE) +
  scale_x_continuous(name='Time (ms)', breaks=seq(0,300,by=100), expand=c(0,0)) +
  scale_y_continuous(name='Scalp Potential (?V)', breaks=seq(-10,10,by=10), expand=c(0,0)) +
  coord_cartesian(xlim=c(0,300), ylim=c(-10,12)) +
  theme(panel.background = element_blank(),
        panel.grid.major.y = element_blank(),
        panel.grid.major.x = element_blank(),
        aspect.ratio = 1.25,
        panel.border = element_rect(colour = "black", fill = NA, size=3.5),
        plot.margin=unit(c(2,2,2,2), "lines"),
        legend.direction = 'vertical',
        axis.text.x = element_text(size=40, colour = "black"),
        axis.text.y = element_text(size=40, colour = "black"),
        axis.title.x = element_blank(),
        axis.title.y = element_blank())

windows()
print(tplot)

if (savePlots == 1) {
  ggsave(filename = paste(imgSaveDir,'ret_s4_AS.svg',sep=""), width=6, height=8, units="in")
}